<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/7/11
 * Time: 9:07
 */

namespace qrcode;
use oss\Oss;
vendor('phpqrcode.phpqrcode');
class QrCode
{
    public $errorCorrectionLevel = 'L';
    public $matrixPointSize      = 5;

    public function create($url){
        $path = ROOT_PATH . 'public' . DS . 'uploads'.DS.'qrcode'.DS;
        if (!is_dir($path)) {
            // 创建文件加
            mkdir($path);
        }
        $name = time() . rand(10000, 9999999) . '.png';
        $filename = $path. $name;
        \QRcode::png($url,$filename,$this->errorCorrectionLevel,$this->matrixPointSize,2);
        if(is_file($filename)){
            $oss_server = new Oss();
            $upload = $oss_server->updateOss($filename,$name);
            if(is_string($upload)){
                return false;
            }
            if(isset($upload['info']['url'])){
                return [$filename,$upload['info']['url']];;
            }
        }
        return false;
    }
}